#
# Makefile
#
shell=cmd
LVGL_DIR = F:/lvgl
SDL2_DIR = $(LVGL_DIR)/SDL2-2.0.18/i686-w64-mingw32
SIMU_DIR = $(LVGL_DIR)/simulator-8x_mingw

LVGL_DIR_NAME = lvgl-8.1.0
LV_DRIVERS_DIR_NAME = lv_drivers
LV_DEMOS_DIR_NAME = lv_demos

CC           = gcc
LIBS        := -llvgl8 -lSDL2 -lm -lgdi32
LDFLAGS     := -L$(SIMU_DIR) -L$(SDL2_DIR)/lib
DEFINES     := -DLV_CONF_INCLUDE_SIMPLE -DLV_LVGL_H_INCLUDE_SIMPLE -DLV_DEMO_CONF_INCLUDE_SIMPLE
INCLUDE     := -I$(SIMU_DIR) -I$(LVGL_DIR) -I$(LVGL_DIR)/$(LVGL_DIR_NAME) -I$(SDL2_DIR)/include
CFLAGS      := -O2 -Wall -W -Wextra -fPIC $(DEFINES)
CXXFLAGS    := -O2 -std=gnu++11 -Wall -W -Wextra -fexceptions -mthreads -fPIC $(DEFINES)
LFLAGS       = -Wl,-s
DEL_FILE     = del
COPY_FILE    = copy
TARGET       = demo
TARGET_SUFIX = .exe
# TARGET_DIR   = $(ROOT_DIR)/bin

#Collect the files to compile

include $(SIMU_DIR)/main/main.mk
# include $(LVGL_DIR)/$(LVGL_DIR_NAME)/lvgl.mk
include $(LVGL_DIR)/$(LV_DRIVERS_DIR_NAME)/lv_drivers.mk
include $(LVGL_DIR)/$(LV_DEMOS_DIR_NAME)/lv_demo.mk


OBJEXT ?= .o

AOBJS = $(ASRCS:.S=$(OBJEXT))
COBJS = $(CSRCS:.c=$(OBJEXT))

MAINOBJ = $(MAINSRC:.c=$(OBJEXT))

SRCS = $(ASRCS) $(CSRCS) $(MAINSRC)
OBJS = $(AOBJS) $(COBJS)

## MAINOBJ -> OBJFILES

all: $(TARGET)

%.o: %.c
	@$(CC)  $(CFLAGS) $(INCLUDE) -c $< -o $@
	@echo "CC $<"
    
$(TARGET): $(AOBJS) $(COBJS) $(MAINOBJ)
	$(CC) $(LFLAGS) -o $@ $(MAINOBJ) $(AOBJS) $(LDFLAGS) $(COBJS) $(LIBS)

clean: 
	$(DEL_FILE) $(TARGET)$(TARGET_SUFIX) $(AOBJS) $(COBJS) main.o mouse_cursor_icon.o
